"""
获取博客标题链接
"""
import requests
import re

"""
<a class="entrylistItemTitle" href="https://www.cnblogs.com/songhaixing/p/15404899.html">
    <span>✍10 pyenv配置及pipenv的使用</span>
</a>

"""
def write_text():
    url_path = r'https://www.cnblogs.com/songhaixing/archive/2021/11.html'
    result = requests.get(url_path)
    html_text = result.text
    print(html_text)
    with open("cnblog_article.txt","w",encoding="utf-8")as f:
        f.write(html_text)

def get_url_title():
    # write_text()
    with open("cnblog_article.txt", "r", encoding="utf-8")as f:
        txt = f.read()
    res_url = re.findall('class="entrylistItemTitle" href="(.*?)">', txt)
    res_title = re.findall('<a class="entrylistItemTitle".*?">\n.*?<span>(.*?)</span>', txt)
    print(res_url)
    print(len(res_url))
    print(res_title)
    print(len(res_title))
    res_sum = zip(res_title,res_url)
    res_dict = dict(res_sum)
    print(res_dict)
    return res_dict


def format_url_article():
    """
    ## [✍08 docker安装问题](https://www.cnblogs.com/songhaixing/p/15404892.html)
    """
    res_dict = get_url_title()
    print(res_dict)
    url_title_list = []
    for k,v in res_dict.items():
        url_title_list.append(f'## [{k}]({v})')
    sort_list = sorted(url_title_list)
    for i in sort_list:
        print(i)



format_url_article()